/*
 * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.micode.notes.gtask.data;

import android.database.Cursor;
import org.json.JSONObject;

/**
 * 抽象节点基类，定义任务节点的基础结构和同步操作
 */
public abstract class Node {
    // 同步动作常量定义
    public static final int SYNC_ACTION_NONE = 0;          // 无同步动作
    public static final int SYNC_ACTION_ADD_REMOTE = 1;    // 远程添加动作
    public static final int SYNC_ACTION_ADD_LOCAL = 2;      // 本地添加动作
    public static final int SYNC_ACTION_DEL_REMOTE = 3;     // 远程删除动作
    public static final int SYNC_ACTION_DEL_LOCAL = 4;      // 本地删除动作
    public static final int SYNC_ACTION_UPDATE_REMOTE = 5;  // 远程更新动作
    public static final int SYNC_ACTION_UPDATE_LOCAL = 6;   // 本地更新动作
    public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;// 更新冲突动作
    public static final int SYNC_ACTION_ERROR = 8;          // 错误动作

    // 节点属性字段
    private String mGid;           // 全局唯一标识符
    private String mName;          // 节点名称
    private long mLastModified;    // 最后修改时间戳
    private boolean mDeleted;      // 删除标记

    /**
     * 构造函数，初始化节点属性默认值
     */
    public Node() {
        mGid = null;        // GID初始为null
        mName = "";         // 名称初始为空字符串
        mLastModified = 0;  // 最后修改时间初始为0
        mDeleted = false;   // 删除标记初始为false
    }

    // 抽象方法定义（需子类实现）
    public abstract JSONObject getCreateAction(int actionId);      // 获取创建动作的JSON
    public abstract JSONObject getUpdateAction(int actionId);      // 获取更新动作的JSON
    public abstract void setContentByRemoteJSON(JSONObject js);    // 从远程JSON设置内容
    public abstract void setContentByLocalJSON(JSONObject js);     // 从本地JSON设置内容
    public abstract JSONObject getLocalJSONFromContent();          // 获取本地JSON表示
    public abstract int getSyncAction(Cursor c);                   // 获取同步动作类型

    // 属性访问方法
    public void setGid(String gid) {
        this.mGid = gid;
    }
    public void setName(String name) {
        this.mName = name;
    }
    public void setLastModified(long lastModified) {
        this.mLastModified = lastModified;
    }
    public void setDeleted(boolean deleted) {
        this.mDeleted = deleted;
    }
    public String getGid() {
        return this.mGid;
    }
    public String getName() {
        return this.mName;
    }
    public long getLastModified() {
        return this.mLastModified;
    }
    public boolean getDeleted() {
        return this.mDeleted;
    }
}
